console.log("fe2131")
// pages/API/video/video.js
const sourceType = [['camera'], ['album'], ['camera', 'album']]
const camera = ['front', 'back', '']
const count = [1,2,3,4,5,6,7,8,9]
const mediaType = [['image'], ['video'],['mix'],['image', 'video'],['image', 'video','mix']]
const sizeType = [['original'], ['compressed'],['original', 'compressed']]

// eslint-disable-next-line
const duration = Array.apply(null, {length: 60}).map(function (n, i) {
  return i + 1
})

Page({
  onShareAppMessage() {
    return {
      title: '拍摄/选择视频',
      path: 'packageAPI/pages/video/video'
    }
  },
  onShow(res){
    console.log("page onShow",res)
    // mp.showToast({
    //   title: '成功',
    //   icon: 'success',
    //   duration: 2000
    // })
  },
  data: {
    sourceTypeIndex: 2,
    sourceType: ['拍摄', '相册', '拍摄或相册'],

    cameraIndex: 2,
    camera: ['前置', '后置', '前置或后置'],

    countIndex: 2,
    count: [1,2,3,4,5,6,7,8,9],

    mediaTypeIndex:2,
    mediaType:['图片', '视频','混合','图片或者视频','图片或者视频或混合'],

    sizeTypeIndex:1,
    sizeType :['原始', '压缩','原始或压缩'],

    durationIndex: 59,
    duration: duration.map(function (t) { return t + '秒' }),

    src_video: '',
    src_iamge: '',
  },
  sourceTypeChange(e) {
    this.setData({
      sourceTypeIndex: e.detail.value
    })
  },
  countChange(e) {
    this.setData({
      countIndex: e.detail.value
    })
  },
  mediaTypeChange(e) {
    this.setData({
      mediaTypeIndex: e.detail.value
    })
  },
  sizeTypeChange(e) {
    this.setData({
      sizeTypeIndex: e.detail.value
    })
  },
  cameraChange(e) {
    this.setData({
      cameraIndex: e.detail.value
    })
  },
  durationChange(e) {
    this.setData({
      durationIndex: e.detail.value
    })
  },
  chooseVideo() {
    const that = this
    mp.chooseMedia({
      sourceType: sourceType[this.data.sourceTypeIndex],
      camera: camera[this.data.cameraIndex],
      maxDuration: duration[this.data.durationIndex],
      count: count[this.data.countIndex],
      mediaType: mediaType[this.data.mediaTypeIndex],
      sizeType: sizeType[this.data.sizeTypeIndex],
      success(res) {
        console.log(res)
        if (res.tempFiles[0].fileType == "video") {
          that.setData({
              src_video: res.tempFiles[0].tempFilePath,
              src_image: res.tempFiles[0].thumbTempFilePath
            })
        } else {
          src_image: res.tempFiles[0].tempFilePath
          that.setData({
              src_image: res.tempFiles[0].tempFilePath
          })
        }
      },
      fail(res) {
        console.log("请求失败")
        console.log(res)
      },
      complete(res) {
        console.log("请求完成")
        console.log(res)
      }
    })
  }
})
